package com.atguigu;

import org.apache.spark.SparkConf;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.util.Properties;

/**
 * @author yhm
 * @create 2022-12-26 14:03
 */
public class Test08_Mysql {
    public static void main(String[] args) {
        // 1. 创建sparkConf配置对象
        SparkConf conf = new SparkConf().setAppName("sql").setMaster("local[*]");

        // 2. 创建sparkSession连接对象
        SparkSession spark = SparkSession.builder().config(conf).getOrCreate();

        // 3. 编写代码
        Properties properties = new Properties();
        properties.setProperty("user","root");
        properties.setProperty("password","123456");

        Dataset<Row> rowDataset = spark
                .read()
                .jdbc("jdbc:mysql://hadoop102:3306", "gmall.user_info", properties);

        rowDataset.printSchema();

        rowDataset.show();

        // 4. 关闭sparkSession
        spark.close();
    }
}
